/**
 * @member {hexToRgba}
 */
export namespace Color {
    export function hexToRgba(hex: string, al: number = 1.0): [number, number, number, number] {
        if(typeof hex != 'string') {
            if(hex[0] > 1 || hex[1] > 1 || hex[2] > 1) {
                return [Number((hex[0] / 255).toFixed(2)), Number((hex[1] / 255).toFixed(2)), Number((hex[0]/ 255).toFixed(2)), al];
            }else{
                // return hex.concat([al])
            }
        }
        // @ts-ignore
        let hexColor = /^#/.test(hex) ? hex.slice(1) : hex,
            alp = hex === 'transparent' ? 0 : Math.ceil(al),
            r, g, b;
        // @ts-ignore
        hexColor = /^[0-9a-f]{3}|[0-9a-f]{6}$/i.test(hexColor) ? hexColor : 'fffff';
        if (hexColor.length === 3) {
            // @ts-ignore
            hexColor = hexColor.replace(/(\w)(\w)(\w)/gi, '$1$1$2$2$3$3');
        }
        r = hexColor.slice(0, 2);
        g = hexColor.slice(2, 4);
        b = hexColor.slice(4, 6);
        r = parseInt(r, 16);
        g = parseInt(g, 16);
        b = parseInt(b, 16);
        return [Number((r / 255).toFixed(2)), Number((g / 255).toFixed(2)), Number((r / 255).toFixed(2)), al];
    }
}

export namespace ArrayHelper {
    export function reshape<T = any>(arr: T[][]): T[] {
        let newArr: T[] = [];
        arr.forEach(item => {
            item.forEach(item2 => {
                newArr.push(item2);
            })
        });
        return newArr;
    }
}